﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Forging2.Common.Forging
{
    class ForgingOPC
    {
        public OpcUaHelper.OpcUaClient opcUaClient;
        public Heating.HeatingWorkpiece CurrentWorkpiece { get; set; }
        public string BaseHeight { get; set; } = "ns=4;i=3";
        public string CurrentHeight { get; set; } = "ns=4;i=8";
        public string RealHeight { get; set; } = "ns=4;i=6";
        public string FixHeight { get; set; } = "ns=4;i=5";
        public string opcMinHeight { get; set; } = "ns=4;i=7";
        public string WorkpieceHeight { get; set; } = "ns=4;i=11";
        public string Temperatures1 { get; set; } = "ns=4;i=12";
        public string Temperatures2 { get; set; } = "2";
        public string ForgingSignal { get; set; } = "ns=4;i=13";
        public string ZeroSignal { get; set; } = "ns=4;i=14";
        public string SelectSignal { get; set; } = "ns=4;i=15";
        public string ForgingFinshedSignal { get; set; } = "ns=4;i=16";

        public ForgingOPC()
        {
            opcUaClient =new OpcUaHelper.OpcUaClient() ;
        }
        public void SubscriptionValue( Action<string, Opc.Ua.Client.MonitoredItem , Opc.Ua.Client.MonitoredItemNotificationEventArgs > subcalback)
        {
            string[] nodeids = new string[] { BaseHeight, CurrentHeight, RealHeight, FixHeight, opcMinHeight, WorkpieceHeight, ForgingSignal,
                ZeroSignal, SelectSignal,Temperatures1,Temperatures2,ForgingFinshedSignal };
            if (!opcUaClient.Connected)
            {
                Const.Front.Notification = "信号尚未连接，请重新运行！";
                return;
            }

            opcUaClient.AddSubscription(Environment.MachineName, nodeids, subcalback);
            //opcUaClientServer.Subscription(nodeids);
        }

    }
}
